<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class GetoptLong - getoptlong: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-GetoptLong-label-Options">Options</a>
    <li><a href="#class-GetoptLong-label-Option+Name+and+Aliases">Option Name and Aliases</a>
    <li><a href="#class-GetoptLong-label-Repetition">Repetition</a>
    <li><a href="#class-GetoptLong-label-Treating+Remaining+Options+as+Arguments">Treating Remaining Options as Arguments</a>
    <li><a href="#class-GetoptLong-label-Option+Types">Option Types</a>
    <li><a href="#class-GetoptLong-label-Option+with+Required+Argument">Option with Required Argument</a>
    <li><a href="#class-GetoptLong-label-Option+with+Optional+Argument">Option with Optional Argument</a>
    <li><a href="#class-GetoptLong-label-Option+with+No+Argument">Option with No Argument</a>
    <li><a href="#class-GetoptLong-label-ARGV">ARGV</a>
    <li><a href="#class-GetoptLong-label-Ordering">Ordering</a>
    <li><a href="#class-GetoptLong-label-PERMUTE+Ordering">PERMUTE Ordering</a>
    <li><a href="#class-GetoptLong-label-REQUIRE_ORDER+Ordering">REQUIRE_ORDER Ordering</a>
    <li><a href="#class-GetoptLong-label-RETURN_IN_ORDER+Ordering">RETURN_IN_ORDER Ordering</a>
    <li><a href="#class-GetoptLong-label-Full+Example">Full Example</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_option">#each_option</a>
    <li ><a href="#method-i-error_message">#error_message</a>
    <li ><a href="#method-i-get">#get</a>
    <li ><a href="#method-i-get_option">#get_option</a>
    <li ><a href="#method-i-ordering-3D">#ordering=</a>
    <li ><a href="#method-i-set_error">#set_error</a>
    <li ><a href="#method-i-set_options">#set_options</a>
    <li ><a href="#method-i-terminate">#terminate</a>
    <li ><a href="#method-i-terminated-3F">#terminated?</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-GetoptLong">
    <h1 id="class-GetoptLong" class="class">
      class GetoptLong
    </h1>

    <section class="description">
    
<p>Class GetoptLong provides parsing both for options and for regular arguments.</p>

<p>Using GetoptLong, you can define options for your program. The program can then capture and respond to whatever options are included in the command that executes the program.</p>

<p>A simple example: file <code>simple.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--number&#39;</span>, <span class="ruby-string">&#39;-n&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--verbose&#39;</span>, <span class="ruby-string">&#39;-v&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--help&#39;</span>, <span class="ruby-string">&#39;-h&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
</pre>

<p>If you are somewhat familiar with options, you may want to skip to this <a href="#class-GetoptLong-label-Full+Example">full example</a>.</p>

<h2 id="class-GetoptLong-label-Options">Options<span><a href="#class-GetoptLong-label-Options">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>A GetoptLong option has:</p>
<ul><li>
<p>A string <em>option name</em>.</p>
</li><li>
<p>Zero or more string <em>aliases</em> for the name.</p>
</li><li>
<p>An <em>option type</em>.</p>
</li></ul>

<p>Options may be defined by calling singleton method <a href="GetoptLong.html#method-c-new"><code>GetoptLong.new</code></a>, which returns a new GetoptLong object. Options may then be processed by calling other methods such as <a href="GetoptLong.html#method-i-each"><code>GetoptLong#each</code></a>.</p>

<h3 id="class-GetoptLong-label-Option+Name+and+Aliases">Option Name and Aliases<span><a href="#class-GetoptLong-label-Option+Name+and+Aliases">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In the array that defines an option, the first element is the string option name. Often the name takes the ‘long’ form, beginning with two hyphens.</p>

<p>The option name may have any number of aliases, which are defined by additional string elements.</p>

<p>The name and each alias must be of one of two forms:</p>
<ul><li>
<p>Two hyphens, followed by one or more letters.</p>
</li><li>
<p>One hyphen, followed by a single letter.</p>
</li></ul>

<p>File <code>aliases.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-string">&#39;-x&#39;</span>, <span class="ruby-string">&#39;--aaa&#39;</span>, <span class="ruby-string">&#39;-a&#39;</span>, <span class="ruby-string">&#39;-p&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
</pre>

<p>An option may be cited by its name, or by any of its aliases; the parsed option always reports the name, not an alias:</p>

<pre>$ ruby aliases.rb -a -p --xxx --aaa -x</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<p>An option may also be cited by an abbreviation of its name or any alias, as long as that abbreviation is unique among the options.</p>

<p>File <code>abbrev.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--xyz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
</pre>

<p>Command line:</p>

<pre>$ ruby abbrev.rb --xxx --xx --xyz --xy</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xyz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xyz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<p>This command line raises <a href="GetoptLong/AmbiguousOption.html"><code>GetoptLong::AmbiguousOption</code></a>:</p>

<pre>$ ruby abbrev.rb --x</pre>

<h3 id="class-GetoptLong-label-Repetition">Repetition<span><a href="#class-GetoptLong-label-Repetition">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An option may be cited more than once:</p>

<pre>$ ruby abbrev.rb --xxx --xyz --xxx --xyz</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xyz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xyz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<h3 id="class-GetoptLong-label-Treating+Remaining+Options+as+Arguments">Treating Remaining Options as Arguments<span><a href="#class-GetoptLong-label-Treating+Remaining+Options+as+Arguments">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A option-like token that appears anywhere after the token <code>--</code> is treated as an ordinary argument, and is not processed as an option:</p>

<pre>$ ruby abbrev.rb --xxx --xyz -- --xxx --xyz</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xyz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<h3 id="class-GetoptLong-label-Option+Types">Option Types<span><a href="#class-GetoptLong-label-Option+Types">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Each option definition includes an option type, which controls whether the option takes an argument.</p>

<p>File <code>types.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
</pre>

<p>Note that an option type has to do with the <em>option argument</em> (whether it is required, optional, or forbidden), not with whether the option itself is required.</p>

<h4 id="class-GetoptLong-label-Option+with+Required+Argument">Option with Required Argument<span><a href="#class-GetoptLong-label-Option+with+Required+Argument">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>An option of type <code>GetoptLong::REQUIRED_ARGUMENT</code> must be followed by an argument, which is associated with that option:</p>

<pre>$ ruby types.rb --xxx foo</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;foo&quot;</span>]
</pre>

<p>If the option is not last, its argument is whatever follows it (even if the argument looks like another option):</p>

<pre>$ ruby types.rb --xxx --yyy</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>]
</pre>

<p>If the option is last, an exception is raised:</p>

<pre>$ ruby types.rb
# Raises GetoptLong::MissingArgument</pre>

<h4 id="class-GetoptLong-label-Option+with+Optional+Argument">Option with Optional Argument<span><a href="#class-GetoptLong-label-Option+with+Optional+Argument">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>An option of type <code>GetoptLong::OPTIONAL_ARGUMENT</code> may be followed by an argument, which if given is associated with that option.</p>

<p>If the option is last, it does not have an argument:</p>

<pre>$ ruby types.rb --yyy</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<p>If the option is followed by another option, it does not have an argument:</p>

<pre>$ ruby types.rb --yyy --zzz</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<p>Otherwise the option is followed by its argument, which is associated with that option:</p>

<pre>$ ruby types.rb --yyy foo</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;foo&quot;</span>]
</pre>

<h4 id="class-GetoptLong-label-Option+with+No+Argument">Option with No Argument<span><a href="#class-GetoptLong-label-Option+with+No+Argument">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>An option of type <code>GetoptLong::NO_ARGUMENT</code> takes no argument:</p>

<pre>ruby types.rb --zzz foo</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
</pre>

<h3 id="class-GetoptLong-label-ARGV">ARGV<span><a href="#class-GetoptLong-label-ARGV">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>You can process options either with method <a href="GetoptLong.html#method-i-each"><code>each</code></a> and a block, or with method <a href="GetoptLong.html#method-i-get"><code>get</code></a>.</p>

<p>During processing, each found option is removed, along with its argument if there is one. After processing, each remaining element was neither an option nor the argument for an option.</p>

<p>File <code>argv.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Original ARGV: #{ARGV}&quot;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Remaining ARGV: #{ARGV}&quot;</span>
</pre>

<p>Command line:</p>

<pre>$ ruby argv.rb --xxx Foo --yyy Bar Baz --zzz Bat Bam</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-constant">Original</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>]
[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>]
[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
<span class="ruby-constant">Remaining</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>]
</pre>

<h3 id="class-GetoptLong-label-Ordering">Ordering<span><a href="#class-GetoptLong-label-Ordering">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>There are three settings that control the way the options are interpreted:</p>
<ul><li>
<p><code>PERMUTE</code>.</p>
</li><li>
<p><code>REQUIRE_ORDER</code>.</p>
</li><li>
<p><code>RETURN_IN_ORDER</code>.</p>
</li></ul>

<p>The initial setting for a new GetoptLong object is <code>REQUIRE_ORDER</code> if environment variable <code>POSIXLY_CORRECT</code> is defined, <code>PERMUTE</code> otherwise.</p>

<h4 id="class-GetoptLong-label-PERMUTE+Ordering">PERMUTE Ordering<span><a href="#class-GetoptLong-label-PERMUTE+Ordering">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In the <code>PERMUTE</code> ordering, options and other, non-option, arguments may appear in any order and any mixture.</p>

<p>File <code>permute.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Original ARGV: #{ARGV}&quot;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Remaining ARGV: #{ARGV}&quot;</span>
</pre>

<p>Command line:</p>

<pre>$ ruby permute.rb Foo --zzz Bar --xxx Baz --yyy Bat Bam --xxx Bag Bah</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-constant">Original</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>, <span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Bag&quot;</span>, <span class="ruby-string">&quot;Bah&quot;</span>]
[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>]
[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Bag&quot;</span>]
<span class="ruby-constant">Remaining</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>, <span class="ruby-string">&quot;Bah&quot;</span>]
</pre>

<h4 id="class-GetoptLong-label-REQUIRE_ORDER+Ordering">REQUIRE_ORDER Ordering<span><a href="#class-GetoptLong-label-REQUIRE_ORDER+Ordering">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In the <code>REQUIRE_ORDER</code> ordering, all options precede all non-options; that is, each word after the first non-option word is treated as a non-option word (even if it begins with a hyphen).</p>

<p>File <code>require_order.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> = <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRE_ORDER</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Original ARGV: #{ARGV}&quot;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Remaining ARGV: #{ARGV}&quot;</span>
</pre>

<p>Command line:</p>

<pre>$ ruby require_order.rb --xxx Foo Bar --xxx Baz --yyy Bat -zzz</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-constant">Original</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;-zzz&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>]
<span class="ruby-constant">Remaining</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;-zzz&quot;</span>]
</pre>

<h4 id="class-GetoptLong-label-RETURN_IN_ORDER+Ordering">RETURN_IN_ORDER Ordering<span><a href="#class-GetoptLong-label-RETURN_IN_ORDER+Ordering">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In the <code>RETURN_IN_ORDER</code> ordering, every word is treated as an option. A word that begins with a hyphen (or two) is treated in the usual way; a word <code>word</code> that does not so begin is treated as an option whose name is an empty string, and whose value is <code>word</code>.</p>

<p>File <code>return_in_order.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> = <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">RETURN_IN_ORDER</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Original ARGV: #{ARGV}&quot;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Remaining ARGV: #{ARGV}&quot;</span>
</pre>

<p>Command line:</p>

<pre>$ ruby return_in_order.rb Foo --xxx Bar Baz --zzz Bat Bam</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-constant">Original</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>]
[<span class="ruby-string">&quot;&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>]
[<span class="ruby-string">&quot;&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>]
[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
[<span class="ruby-string">&quot;&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>]
[<span class="ruby-string">&quot;&quot;</span>, <span class="ruby-string">&quot;Bam&quot;</span>]
<span class="ruby-constant">Remaining</span> <span class="ruby-value">ARGV:</span> []
</pre>

<h3 id="class-GetoptLong-label-Full+Example">Full Example<span><a href="#class-GetoptLong-label-Full+Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>File <code>fibonacci.rb</code>:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--number&#39;</span>, <span class="ruby-string">&#39;-n&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--verbose&#39;</span>, <span class="ruby-string">&#39;-v&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--help&#39;</span>, <span class="ruby-string">&#39;-h&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)

<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">help</span>(<span class="ruby-identifier">status</span> = <span class="ruby-value">0</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">&lt;&lt;~HELP</span>
<span class="ruby-value">    Usage:

      -n n, --number n:
        Compute Fibonacci number for n.
      -v [boolean], --verbose [boolean]:
        Show intermediate results; default is &#39;false&#39;.
      -h, --help:
        Show this help.
</span><span class="ruby-identifier">  HELP</span>
  <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_fibonacci</span> (<span class="ruby-identifier">number</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-value">0</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">number</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">number</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">number</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">j</span> = <span class="ruby-value">1</span>
  (<span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-identifier">number</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">k</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">j</span>
    <span class="ruby-identifier">i</span> = <span class="ruby-identifier">j</span>
    <span class="ruby-identifier">j</span> = <span class="ruby-identifier">k</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-identifier">j</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@verbose</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">j</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@verbose</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">option</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&#39;--number&#39;</span>
    <span class="ruby-ivar">@number</span> = <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&#39;--verbose&#39;</span>
    <span class="ruby-ivar">@verbose</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/true/i</span>)
      <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">argument</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/false/i</span>)
      <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-string">&#39;--verbose argument must be true or false&#39;</span>
      <span class="ruby-identifier">help</span>(<span class="ruby-value">255</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&#39;--help&#39;</span>
    <span class="ruby-identifier">help</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@number</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&#39;Option --number is required.&#39;</span>
  <span class="ruby-identifier">help</span>(<span class="ruby-value">255</span>)
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">print_fibonacci</span>(<span class="ruby-ivar">@number</span>)
</pre>

<p>Command line:</p>

<pre>$ ruby fibonacci.rb</pre>

<p>Output:</p>

<pre>Option --number is required.
Usage:

  -n n, --number n:
    Compute Fibonacci number for n.
  -v [boolean], --verbose [boolean]:
    Show intermediate results; default is &#39;false&#39;.
  -h, --help:
    Show this help.</pre>

<p>Command line:</p>

<pre>$ ruby fibonacci.rb --number</pre>

<p>Raises <a href="GetoptLong/MissingArgument.html"><code>GetoptLong::MissingArgument</code></a>:</p>

<pre>fibonacci.rb: option `--number&#39; requires an argument</pre>

<p>Command line:</p>

<pre>$ ruby fibonacci.rb --number 6</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-value">8</span>
</pre>

<p>Command line:</p>

<pre>$ ruby fibonacci.rb --number 6 --verbose</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-value">1</span>
<span class="ruby-value">2</span>
<span class="ruby-value">3</span>
<span class="ruby-value">5</span>
<span class="ruby-value">8</span>
</pre>

<p>Command line:</p>

<pre>$ ruby fibonacci.rb --number 6 --verbose yes</pre>

<p>Output:</p>

<pre>--verbose argument must be true or false
Usage:

  -n n, --number n:
    Compute Fibonacci number for n.
  -v [boolean], --verbose [boolean]:
    Show intermediate results; default is &#39;false&#39;.
  -h, --help:
    Show this help.</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="ARGUMENT_FLAGS">ARGUMENT_FLAGS
          <dd><p>Argument flags.</p>
          <dt id="ORDERINGS">ORDERINGS
          <dd><p>Orderings.</p>
          <dt id="STATUS_TERMINATED">STATUS_TERMINATED
          <dd>
          <dt id="VERSION">VERSION
          <dd><p>Version.</p>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-error" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">error</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns whether option processing has failed.</p>
              </div>
            </div>
          <div id="attribute-i-error-3F" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">error?</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns whether option processing has failed.</p>
              </div>
            </div>
          <div id="attribute-i-ordering" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ordering</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the ordering setting.</p>
              </div>
            </div>
          <div id="attribute-i-quiet" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">quiet</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets quiet mode and returns the given argument:</p>
<ul><li>
<p>When <code>false</code> or <code>nil</code>, error messages are written to <code>$stdout</code>.</p>
</li><li>
<p>Otherwise, error messages are not written.</p>
</li></ul>
              </div>
            </div>
          <div id="attribute-i-quiet-3F" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">quiet?</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets quiet mode and returns the given argument:</p>
<ul><li>
<p>When <code>false</code> or <code>nil</code>, error messages are written to <code>$stdout</code>.</p>
</li><li>
<p>Otherwise, error messages are not written.</p>
</li></ul>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(*arguments)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new GetoptLong object based on the given <code>arguments</code>. See <a href="#class-GetoptLong-label-Options">Options</a>.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--number&#39;</span>, <span class="ruby-string">&#39;-n&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--verbose&#39;</span>, <span class="ruby-string">&#39;-v&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--help&#39;</span>, <span class="ruby-string">&#39;-h&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
</pre>

<p>Raises an exception if:</p>
<ul><li>
<p>Any of <code>arguments</code> is not an array.</p>
</li><li>
<p>Any option name or alias is not a string.</p>
</li><li>
<p>Any option type is invalid.</p>
</li></ul>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 412</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Current ordering.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;POSIXLY_CORRECT&#39;</span>)
    <span class="ruby-ivar">@ordering</span> = <span class="ruby-constant">REQUIRE_ORDER</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@ordering</span> = <span class="ruby-constant">PERMUTE</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Hash table of option names.</span>
  <span class="ruby-comment"># Keys of the table are option names, and their values are canonical</span>
  <span class="ruby-comment"># names of the options.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@canonical_names</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Hash table of argument flags.</span>
  <span class="ruby-comment"># Keys of the table are option names, and their values are argument</span>
  <span class="ruby-comment"># flags of the options.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@argument_flags</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Whether error messages are output to $stderr.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@quiet</span> = <span class="ruby-keyword">false</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Status code.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@status</span> = <span class="ruby-constant">STATUS_YET</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Error code.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@error</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Error message.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@error_message</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Rest of catenated short options.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-string">&#39;&#39;</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># List of non-option-arguments.</span>
  <span class="ruby-comment"># Append them to ARGV when option processing is terminated.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@non_option_arguments</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>

  <span class="ruby-keyword">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">length</span>
    <span class="ruby-identifier">set_options</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-each" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">() { |option_name, option_argument| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with each option; each option is a 2-element array containing:</p>
<ul><li>
<p>The option name (the name itself, not an alias).</p>
</li><li>
<p>The option value.</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;getoptlong&#39;</span>

<span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>(
  [<span class="ruby-string">&#39;--xxx&#39;</span>, <span class="ruby-string">&#39;-x&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRED_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--yyy&#39;</span>, <span class="ruby-string">&#39;-y&#39;</span>, <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">OPTIONAL_ARGUMENT</span>],
  [<span class="ruby-string">&#39;--zzz&#39;</span>, <span class="ruby-string">&#39;-z&#39;</span>,<span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_ARGUMENT</span>]
)
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Original ARGV: #{ARGV}&quot;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> [<span class="ruby-identifier">option</span>, <span class="ruby-identifier">argument</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Remaining ARGV: #{ARGV}&quot;</span>
</pre>

<p>Command line:</p>

<pre>ruby each.rb -xxx Foo -x Bar --yyy Baz -y Bat --zzz</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-constant">Original</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;-xxx&quot;</span>, <span class="ruby-string">&quot;Foo&quot;</span>, <span class="ruby-string">&quot;-x&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>, <span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>, <span class="ruby-string">&quot;-y&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>, <span class="ruby-string">&quot;--zzz&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;xx&quot;</span>]
[<span class="ruby-string">&quot;--xxx&quot;</span>, <span class="ruby-string">&quot;Bar&quot;</span>]
[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Baz&quot;</span>]
[<span class="ruby-string">&quot;--yyy&quot;</span>, <span class="ruby-string">&quot;Bat&quot;</span>]
[<span class="ruby-string">&quot;--zzz&quot;</span>, <span class="ruby-string">&quot;&quot;</span>]
<span class="ruby-constant">Remaining</span> <span class="ruby-value">ARGV:</span> [<span class="ruby-string">&quot;Foo&quot;</span>]
</pre>

                              <div class="method-source-code" id="each-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 859</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each</span>
  <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">option_name</span>, <span class="ruby-identifier">option_argument</span> = <span class="ruby-identifier">get_option</span>
    <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">option_name</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">option_name</span>, <span class="ruby-identifier">option_argument</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="GetoptLong.html#method-i-each_option">each_option</a>
                            </div>

                          </div>

                  <div id="method-i-each_option" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">each_option</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="GetoptLong.html#method-i-each">each</a>
                            </div>
                          </div>

                  <div id="method-i-error_message" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">error_message</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return the appropriate error message in POSIX-defined format. If no error has occurred, returns <code>nil</code>.</p>

                              <div class="method-source-code" id="error_message-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 662</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">error_message</span>
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@error_message</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">get</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the next option as a 2-element array containing:</p>
<ul><li>
<p>The option name (the name itself, not an alias).</p>
</li><li>
<p>The option value.</p>
</li></ul>

<p>Returns <code>nil</code> if there are no more options.</p>

                              <div class="method-source-code" id="get-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 674</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get</span>
  <span class="ruby-identifier">option_name</span>, <span class="ruby-identifier">option_argument</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;&#39;</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Check status.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@error</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">case</span> <span class="ruby-ivar">@status</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">STATUS_YET</span>
    <span class="ruby-ivar">@status</span> = <span class="ruby-constant">STATUS_STARTED</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">STATUS_TERMINATED</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Get next option argument.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@rest_singles</span>.<span class="ruby-identifier">length</span>
    <span class="ruby-identifier">argument</span> = <span class="ruby-string">&#39;-&#39;</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@rest_singles</span>
  <span class="ruby-keyword">elsif</span> (<span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">terminate</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">PERMUTE</span>
    <span class="ruby-keyword">while</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">ARGV</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\A-./</span>
      <span class="ruby-ivar">@non_option_arguments</span>.<span class="ruby-identifier">push</span>(<span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">terminate</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">REQUIRE_ORDER</span>
    <span class="ruby-keyword">if</span> (<span class="ruby-constant">ARGV</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\A-./</span>)
      <span class="ruby-identifier">terminate</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Check the special argument `--&#39;.</span>
  <span class="ruby-comment"># `--&#39; indicates the end of the option list.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;--&#39;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@rest_singles</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">terminate</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Check for long and short options.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\A(--[^=]+)/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@rest_singles</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># This is a long style option, which start with `--&#39;.</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-identifier">pattern</span> = <span class="ruby-node">$1</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">pattern</span>)
      <span class="ruby-identifier">option_name</span> = <span class="ruby-identifier">pattern</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># The option `option_name&#39; is not registered in `@canonical_names&#39;.</span>
      <span class="ruby-comment"># It may be an abbreviated.</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-identifier">matches</span> = []
      <span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">pattern</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
          <span class="ruby-identifier">option_name</span> = <span class="ruby-identifier">key</span>
          <span class="ruby-identifier">matches</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">key</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">if</span> <span class="ruby-value">2</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">length</span>
        <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">AmbiguousOption</span>, <span class="ruby-node">&quot;option `#{argument}&#39; is ambiguous between #{matches.join(&#39;, &#39;)}&quot;</span>)
      <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">matches</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">InvalidOption</span>, <span class="ruby-node">&quot;unrecognized option `#{argument}&#39;&quot;</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># Check an argument to the option.</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@argument_flags</span>[<span class="ruby-identifier">option_name</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">REQUIRED_ARGUMENT</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/=(.*)/m</span>
        <span class="ruby-identifier">option_argument</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">elsif</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span>
        <span class="ruby-identifier">option_argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">MissingArgument</span>,
                  <span class="ruby-node">&quot;option `#{argument}&#39; requires an argument&quot;</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@argument_flags</span>[<span class="ruby-identifier">option_name</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">OPTIONAL_ARGUMENT</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/=(.*)/m</span>
        <span class="ruby-identifier">option_argument</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">elsif</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">ARGV</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\A-./</span>
        <span class="ruby-identifier">option_argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">option_argument</span> = <span class="ruby-string">&#39;&#39;</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/=(.*)/m</span>
      <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">NeedlessArgument</span>,
                <span class="ruby-node">&quot;option `#{option_name}&#39; doesn&#39;t allow an argument&quot;</span>)
    <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">argument</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\A(-(.))(.*)/m</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># This is a short style option, which start with `-&#39; (not `--&#39;).</span>
    <span class="ruby-comment"># Short options may be catenated (e.g. `-l -g&#39; is equivalent to</span>
    <span class="ruby-comment"># `-lg&#39;).</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-identifier">option_name</span>, <span class="ruby-identifier">ch</span>, <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>, <span class="ruby-node">$3</span>

    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">option_name</span>)
      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># The option `option_name&#39; is found in `@canonical_names&#39;.</span>
      <span class="ruby-comment"># Check its argument.</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@argument_flags</span>[<span class="ruby-identifier">option_name</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">REQUIRED_ARGUMENT</span>
        <span class="ruby-keyword">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@rest_singles</span>.<span class="ruby-identifier">length</span>
          <span class="ruby-identifier">option_argument</span> = <span class="ruby-ivar">@rest_singles</span>
          <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-string">&#39;&#39;</span>
        <span class="ruby-keyword">elsif</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span>
          <span class="ruby-identifier">option_argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-comment"># 1003.2 specifies the format of this message.</span>
          <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">MissingArgument</span>, <span class="ruby-node">&quot;option requires an argument -- #{ch}&quot;</span>)
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@argument_flags</span>[<span class="ruby-identifier">option_name</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">OPTIONAL_ARGUMENT</span>
        <span class="ruby-keyword">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@rest_singles</span>.<span class="ruby-identifier">length</span>
          <span class="ruby-identifier">option_argument</span> = <span class="ruby-ivar">@rest_singles</span>
          <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-string">&#39;&#39;</span>
        <span class="ruby-keyword">elsif</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">ARGV</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\A-./</span>
          <span class="ruby-identifier">option_argument</span> = <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">shift</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">option_argument</span> = <span class="ruby-string">&#39;&#39;</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># This is an invalid option.</span>
      <span class="ruby-comment"># 1003.2 specifies the format of this message.</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;POSIXLY_CORRECT&#39;</span>)
        <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">InvalidOption</span>, <span class="ruby-node">&quot;invalid option -- #{ch}&quot;</span>)
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">InvalidOption</span>, <span class="ruby-node">&quot;invalid option -- #{ch}&quot;</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># This is a non-option argument.</span>
    <span class="ruby-comment"># Only RETURN_IN_ORDER fell into here.</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-keyword">return</span> <span class="ruby-string">&#39;&#39;</span>, <span class="ruby-identifier">argument</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@canonical_names</span>[<span class="ruby-identifier">option_name</span>], <span class="ruby-identifier">option_argument</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="GetoptLong.html#method-i-get_option">get_option</a>
                            </div>

                          </div>

                  <div id="method-i-get_option" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">get_option</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="GetoptLong.html#method-i-get">get</a>
                            </div>
                          </div>

                  <div id="method-i-ordering-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">ordering=</span><span
                                class="method-args">(ordering)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the ordering; see <a href="#class-GetoptLong-label-Ordering">Ordering</a>; returns the new ordering.</p>

<p>If the given <code>ordering</code> is <code>PERMUTE</code> and environment variable <code>POSIXLY_CORRECT</code> is defined, sets the ordering to <code>REQUIRE_ORDER</code>; otherwise sets the ordering to <code>ordering</code>:</p>

<pre class="ruby"><span class="ruby-identifier">options</span> = <span class="ruby-constant">GetoptLong</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">PERMUTE</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> = <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">RETURN_IN_ORDER</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">RETURN_IN_ORDER</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">ENV</span>[<span class="ruby-string">&#39;POSIXLY_CORRECT&#39;</span>] = <span class="ruby-string">&#39;true&#39;</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> = <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">PERMUTE</span>
<span class="ruby-identifier">options</span>.<span class="ruby-identifier">ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">GetoptLong</span><span class="ruby-operator">::</span><span class="ruby-constant">REQUIRE_ORDER</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Raises an exception if <code>ordering</code> is invalid.</p>

                              <div class="method-source-code" id="ordering-3D-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 489</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ordering=</span>(<span class="ruby-identifier">ordering</span>)
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># The method is failed if option processing has already started.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@status</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">STATUS_YET</span>
    <span class="ruby-identifier">set_error</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;argument error&quot;</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>,
      <span class="ruby-string">&quot;invoke ordering=, but option processing has already started&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Check ordering.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">ORDERINGS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">ordering</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;invalid ordering `#{ordering}&#39;&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">ordering</span> <span class="ruby-operator">==</span> <span class="ruby-constant">PERMUTE</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;POSIXLY_CORRECT&#39;</span>)
    <span class="ruby-ivar">@ordering</span> = <span class="ruby-constant">REQUIRE_ORDER</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@ordering</span> = <span class="ruby-identifier">ordering</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_options" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_options</span><span
                                class="method-args">(*arguments)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Replaces existing options with those given by <code>arguments</code>, which have the same form as the arguments to <a href="GetoptLong.html#method-c-new"><code>::new</code></a>; returns <code>self</code>.</p>

<p>Raises an exception if option processing has begun.</p>

                              <div class="method-source-code" id="set_options-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 524</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_options</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># The method is failed if option processing has already started.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@status</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">STATUS_YET</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>,
      <span class="ruby-string">&quot;invoke set_options, but option processing has already started&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Clear tables of option names and argument flags.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-ivar">@argument_flags</span>.<span class="ruby-identifier">clear</span>

  <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">arg</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
     <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;the option list contains non-Array argument&quot;</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># Find an argument flag and it set to `argument_flag&#39;.</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-identifier">argument_flag</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGUMENT_FLAGS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">i</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument_flag</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;too many argument-flags&quot;</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">argument_flag</span> = <span class="ruby-identifier">i</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;no argument-flag&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">argument_flag</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>

    <span class="ruby-identifier">canonical_name</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># Check an option name.</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">argument_flag</span>
      <span class="ruby-keyword">begin</span>
        <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">i</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp">/\A-([^-]|-.+)\z/</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;an invalid option `#{i}&#39;&quot;</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">if</span> (<span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">i</span>))
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;option redefined `#{i}&#39;&quot;</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">rescue</span>
        <span class="ruby-ivar">@canonical_names</span>.<span class="ruby-identifier">clear</span>
        <span class="ruby-ivar">@argument_flags</span>.<span class="ruby-identifier">clear</span>
        <span class="ruby-identifier">raise</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-comment">#</span>
      <span class="ruby-comment"># Register the option (`i&#39;) to the `@canonical_names&#39; and</span>
      <span class="ruby-comment"># `@canonical_names&#39; Hashes.</span>
      <span class="ruby-comment">#</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">canonical_name</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
        <span class="ruby-identifier">canonical_name</span> = <span class="ruby-identifier">i</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@canonical_names</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">canonical_name</span>
      <span class="ruby-ivar">@argument_flags</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">argument_flag</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;no option name&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">canonical_name</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-terminate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">terminate</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Terminate option processing; returns <code>nil</code> if processing has already terminated; otherwise returns <code>self</code>.</p>

                              <div class="method-source-code" id="terminate-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 612</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">terminate</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@status</span> <span class="ruby-operator">==</span> <span class="ruby-constant">STATUS_TERMINATED</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">&quot;an error has occurred&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@error</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>

  <span class="ruby-ivar">@status</span> = <span class="ruby-constant">STATUS_TERMINATED</span>
  <span class="ruby-ivar">@non_option_arguments</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">argument</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">argument</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@canonical_names</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@argument_flags</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@non_option_arguments</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-terminated-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">terminated?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if option processing has terminated, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="terminated-3F-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 632</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">terminated?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@status</span> <span class="ruby-operator">==</span> <span class="ruby-constant">STATUS_TERMINATED</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="protected-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Protected Instance Methods</h3>
                </header>

                  <div id="method-i-set_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_error</span><span
                                class="method-args">(type, message)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set an error (a protected method).</p>

                              <div class="method-source-code" id="set_error-source">
            <pre><span class="ruby-comment"># File getoptlong.rb, line 639</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_error</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">message</span>)
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-node">&quot;#{$0}: #{message}\n&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@quiet</span>

  <span class="ruby-ivar">@error</span> = <span class="ruby-identifier">type</span>
  <span class="ruby-ivar">@error_message</span> = <span class="ruby-identifier">message</span>
  <span class="ruby-ivar">@canonical_names</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@argument_flags</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@rest_singles</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@non_option_arguments</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-identifier">type</span>, <span class="ruby-identifier">message</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

